#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n,m;
vector<char> ch[N];
namespace sub1{
	vector<char> ans[N];
	int lim;
	void work(int cnt)
	{
		for(int i = 1;i<=n;i++)
			for(int j = 1;j<=m;j++)
				if(ans[i][j]=='0'&&ans[i][j-1]!='1'&&ans[i][j+1]!='1'&&ans[i-1][j]!='1'&&ans[i+1][j]!='1') return;
		for(int i = 1;i<=n;i++,cout<<'\n')
			for(int j = 1;j<=m;j++)
				cout<<ans[i][j];
		exit(0);
	}
	void dfs(int x,int y,int cnt)
	{
		if(cnt>lim) return;
		if(y>m) return dfs(x+1,1,cnt);
		if(x>n) return work(cnt);
		if(ch[x][y]=='.')
		{
			ans[x][y] = '.';
			dfs(x,y+1,cnt);
		}
		else
		{
			ans[x][y] = '0';
			dfs(x,y+1,cnt);
			ans[x][y] = '1';
			dfs(x,y+1,cnt+1);
		}
	}
	inline void main()
	{
		for(int i = 0;i<=n+1;i++)
			ans[i].resize(m+2);
		for(int i = 1;i<=n;i++)
			for(int j = 1;j<=m;j++)
				if(ch[i][j]=='#')
				{
					lim++;
					lim+=ch[i-1][j]!='#';
					lim+=ch[i+1][j]!='#';
					lim+=ch[i][j+1]!='#';
					lim+=ch[i][j-1]!='#';
				}
		lim/=5;
		cerr<<lim<<'\n';
		dfs(1,1,0);
	}
}
namespace sub2{
	inline void main()
	{
		for(int i = 1;i<=n;i++,cout<<'\n')
			for(int j = 1;j<=m;j++)
				if(ch[i][j]=='#') cout<<'1';
				else cout<<'.';
	}
}
namespace sub3{
	set<pair<pair<int,int>,pair<int,int>>> s;
	inline void ins(int x,int y)
	{
		if(ch[x][y]!='#') return;
		int res = 1,res2 = 1;
		if(ch[x-1][y]=='#')
		{
			res2++;
			res++;
			if(ch[x-2][y]=='#') res--;
			else res++;
			if(ch[x-1][y-1]=='#') res--;
			else res++;
			if(ch[x-1][y+1]=='#') res--;
			else res++;
		}
		else res++;
		if(ch[x+1][y]=='#')
		{
			res2++;
			res++;
			if(ch[x+2][y]=='#') res--;
			else res++;
			if(ch[x+1][y-1]=='#') res--;
			else res++;
			if(ch[x+1][y+1]=='#') res--;
			else res++;
		}
		else res++;
		if(ch[x][y-1]=='#')
		{
			res2++;
			res++;
			if(ch[x][y-2]=='#') res--;
			else res++;
			if(ch[x-1][y-1]=='#') res--;
			else res++;
			if(ch[x+1][y-1]=='#') res--;
			else res++;
		}
		else res++;
		if(ch[x][y+1]=='#')
		{
			res2++;
			res++;
			if(ch[x][y+2]=='#') res--;
			else res++;
			if(ch[x-1][y+1]=='#') res--;
			else res++;
			if(ch[x+1][y+1]=='#') res--;
			else res++;
		}
		else res++;
		s.insert({{res,res2},{x,y}});
	}
	inline void del(int x,int y)
	{
		if(ch[x][y]!='#') return;
		int res = 1,res2 = 1;
		if(ch[x-1][y]=='#')
		{
			res2++;
			res++;
			if(ch[x-2][y]=='#') res--;
			else res++;
			if(ch[x-1][y-1]=='#') res--;
			else res++;
			if(ch[x-1][y+1]=='#') res--;
			else res++;
		}
		else res++;
		if(ch[x+1][y]=='#')
		{
			res2++;
			res++;
			if(ch[x+2][y]=='#') res--;
			else res++;
			if(ch[x+1][y-1]=='#') res--;
			else res++;
			if(ch[x+1][y+1]=='#') res--;
			else res++;
		}
		else res++;
		if(ch[x][y-1]=='#')
		{
			res2++;
			res++;
			if(ch[x][y-2]=='#') res--;
			else res++;
			if(ch[x-1][y-1]=='#') res--;
			else res++;
			if(ch[x+1][y-1]=='#') res--;
			else res++;
		}
		else res++;
		if(ch[x][y+1]=='#')
		{
			res2++;
			res++;
			if(ch[x][y+2]=='#') res--;
			else res++;
			if(ch[x-1][y+1]=='#') res--;
			else res++;
			if(ch[x+1][y+1]=='#') res--;
			else res++;
		}
		else res++;
		s.erase({{res,res2},{x,y}});
	}
	inline void main()
	{
		for(int i = 1;i<=n;i++)
			for(int j = 1;j<=m;j++)
				ins(i,j);
		while(!s.empty())
		{
			auto _ = (*(--s.end())).second;
//			cout<<(*(--s.end())).first.first<<'\n';
			s.erase(--s.end());
			int x = _.first,y = _.second;
//			cout<<"xx"<<x<<' '<<y<<'\n';
			for(int i = max(1,x-2);i<=min(n,x+2);i++)
			{
				int now = 2-abs(i-x); 
				for(int j = max(1,y-now);j<=min(m,y+now);j++)
					del(i,j);
			}
			ch[x][y] = '1';
			if(ch[x-1][y]=='#') ch[x-1][y] = '0';
			if(ch[x+1][y]=='#') ch[x+1][y] = '0';
			if(ch[x][y-1]=='#') ch[x][y-1] = '0';
			if(ch[x][y+1]=='#') ch[x][y+1] = '0';
			for(int i = max(1,x-2);i<=min(n,x+2);i++)
			{
				int now = 2-abs(i-x); 
				for(int j = max(1,y-now);j<=min(m,y+now);j++)
					ins(i,j);
			}
		}
		for(int i = 1;i<=n;i++,cout<<'\n')
			for(int j = 1;j<=m;j++)
				cout<<ch[i][j];
	}
}
signed main()
{
	freopen("indian.in","r",stdin);
	freopen("indian.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i = 0;i<=n+1;i++) ch[i].resize(m+2);
	for(int i = 1;i<=n;i++)
		for(int j = 1;j<=m;j++)
			cin>>ch[i][j];
	bool fl = 1;
	for(int i = 1;i<=n;i++)
		for(int j = 1;j<=m;j++)
		{
			if(ch[i][j]!='#') continue;
			if(ch[i][j]==ch[i+1][j]) fl = 0;
			if(ch[i][j]==ch[i][j+1]) fl = 0;
		}
	if(n*m<=20) sub1::main();
	else if(fl) sub2::main();
	else sub3::main();
	return 0;
}

